// JavaScript Document

$(function() {
	
	if(checkVideo()){
		//支持
		lazyBG();
		video_width();

	 	$(window).on('scroll',function(){ 
			lazyBG();
		});
		/**/
	}else{
		//不支持
	 
	}
	
}); 

//检测是否支持HTML5
function checkVideo() {
    if (!!document.createElement('video').canPlayType) {
        var vidTest = document.createElement("video");
        oggTest = vidTest.canPlayType('video/ogg; codecs="theora, vorbis"');
        if (!oggTest) {
            h264Test = vidTest.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
            if (!h264Test) {
                return false;
            }
            else {
                if (h264Test == "probably") {
                    return true;
                }
                else {
                    return false;
                }
            }
        }
        else {
            if (oggTest == "probably") {
                return true;
            }
            else {
               return false;
            }
        }
    }
    else {
        return false;
    }
}

	function video_width(){
		var win_w=$(window).width();
		if(win_w<=1920){
			var video_w=(1920-win_w)/2;
			$(".video_06 video").css("margin-right",-video_w+"px");
			$(".video_left video").css("margin-left",-video_w+"px");
		}
	}
	
	
	function lazyBG(){ 
		$(".video_play").each(function(){
			var a=$(this);
			if($(window).scrollTop() + $(window).height() -a.offset().top >-300){
				a.attr("preload","auto");
				a.attr("autoplay","autoplay");
			} 
		}); 
	}
	/**/
